<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-06 00:34:26
 * @LastEditTime : 2019-12-28 10:51:49
 * @LastEditors  : Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0,viewport-fit=cover" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <style type="text/css">
        .van-cell__title {
            max-width: none;
        }

        .content {
            background: #fff !important;
        }

        .mask {
            background: transparent;
        }

        .left-page {
            background: #fff;
            border-right: 4px solid #ff9699;
            width: 200px;
            height: 100%;
            position: absolute;
            z-index: 99999999;
            left: -196px;
            top: 0;
            transition: all .4s;
            padding-right: 1px;
        }

        .left-page-show {
            left: 0;
            border-color: #fff;
        }

        .arrow {
            right: -28px;
            top: 50%;
            margin-top: -26px;
            position: absolute;
            width: 24px;
        }

        .arrow img {
            width: 12px;
        }

        .module {
            text-align: center;
            margin-top: 10px;
            background: #ffffff;
            color: #3a3a3a;
        }

        .img {
            width: 50px;
            height: 50px;
            text-align: center;
            border-radius: 25px;
            padding: 11px;
            position: relative;
        }

        .img img {
            height: 28px;
            vertical-align: middle;
        }

        .img-text {
            font-size: 14px;
            margin-top: 6px;
        }

        .undeal {
            position: absolute;
            right: -4px;
            top: -4px;
            color: #fff;
            background: #cd1b21;
            width: 20px;
            height: 20px;
            line-height: 20px;
            text-align: center;
            border-radius: 100px;
            font-size: 13px;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="init-full">
            <van-nav-bar class="head" title="栏目"></van-nav-bar>
            <div class="body-no-bottom">
                <div class="content">

                    <div class="module">
                        <van-grid :column-num="4" :border="false">
                            <van-grid-item v-for="row in showList" v-if="row.FunType || row.AP_Link"
                                @click="openPage(row)">
                                <div class="img" :style="{background:row.AP_Colour}">
                                    <img :src="row.PIC_PH || '../image/module/module_default.png'" />
                                    <div class="undeal" v-show="row.unDealNum">{{row.unDealNum}}
                                    </div>
                                </div>
                                <div class="img-text">{{row.APFunName}}</div>
                            </van-grid-item>
                        </van-grid>
                    </div>


                    <div class="mask" v-show="showLeftPage" @click="showLeftPage = !showLeftPage"></div>
                    <div class="left-page" :class="showLeftPage?'left-page-show':''">
                        <div class="page-full">
                            <van-cell :title="row.TreeName" is-link v-for="row in moduleList" @click="toggleTree(row)">
                            </van-cell>
                        </div>
                        <div class="arrow" @click="showLeftPage = !showLeftPage">
                            <img :src="showLeftPage?'../image/retract_.png':'../image/open_.png'" />
                        </div>
                    </div>
                </div>
                <van-loading v-if="showLoading" />
            </div>
        </div>
    </div>
</body>
<script type="text/javascript">
    var vm;
    apiready = function () {
        //$('.init-full').show();

        var userInfo = FLD.getUserInfo();

        vm = new Vue({
            el: '#app',
            data: {
                showLoading: false,
                showLeftPage: false,
                moduleList: [],
                showList: []
            },
            created: function () {
                var that = this;
                that.getModuleList();
                setInterval(function () {
                    that.getUndealNum();
                }, 5000)

            },
            methods: {
                getModuleList() {
                    var that = this;
                    FLD.ajax('AP_GetUserNM', {}, function (res) {
                        var moduleList = [];
                        for (var i in res.ds1) {
                            var x = 0;
                            for (var j in moduleList) {
                                if (res.ds1[i].TreeName == moduleList[j].TreeName) {
                                    x = 1;
                                    moduleList[j].node.push(res.ds1[i])
                                }
                            }
                            if (x == 0) {
                                moduleList.push({
                                    TreeName: res.ds1[i].TreeName,
                                    node: [res.ds1[i]]
                                })
                            }
                        }

                        that.moduleList = moduleList;
                        if (that.moduleList.length > 0) {
                            that.showList = that.moduleList[0].node
                        }
                    })
                },
                openPage(row) {
                    var pageParam = {}
                    if (row.Para) {
                        var paraArray = row.Para.split(';');
                        for (var i in paraArray) {
                            var paraRowArray = paraArray[i].split('=');
                            pageParam[paraRowArray[0]] = paraRowArray[1]
                        }
                    }
                    pageParam.titleName = row.APFunName;
                    if (row.FunType == '自定义') {
                        if (row.AP_Link == 'trip/branchList') {
                            var obj = {
                                S_Type: 666,
                                S_Cont: '',
                                S_BranchID: userInfo.S_BranchID,
                                S_SXZ: '',
                                S_StockID: userInfo.S_StockID,
                                S_CargoID: userInfo.S_CargoID,
                                S_BarCode: '',
                                S_PriceN: 0,
                                S_ProductID: 0
                            }
                            FLD.ajax('AP_BasList', obj, function (res) {
                                var filterResult = res.ds;
                                if (filterResult.length == 1) {
                                    api.openWin({
                                        name: 'tripList',
                                        url: 'trip/tripList.html',
                                        reload: true,
                                        slidBackEnabled: false,
                                        allowEdit: false,
                                        pageParam: {
                                            branchData: filterResult[0]
                                        }
                                    })
                                } else {
                                    api.openWin({
                                        name: row.AP_Link,
                                        url: row.AP_Link + '.html',
                                        reload: true,
                                        slidBackEnabled: false,
                                        allowEdit: row.AP_Link == 'vin' ? true : false,
                                        pageParam: pageParam
                                    })
                                }
                            })
                        } else {
                            api.openWin({
                                name: row.AP_Link,
                                url: row.AP_Link + '.html',
                                reload: true,
                                slidBackEnabled: false,
                                allowEdit: row.AP_Link == 'vin' ? true : false,
                                pageParam: pageParam
                            })
                        }

                    } else if (row.FunType == '配置表单') {
                        api.openWin({
                            name: 'formConfig',
                            url: 'common/formConfig.html',
                            reload: true,
                            slidBackEnabled: false,
                            pageParam: pageParam
                        })
                    } else if (row.FunType == '配置列表') {
                        api.openWin({
                            name: 'formHistoricalDocuments',
                            url: 'common/formHistoricalDocuments.html',
                            reload: true,
                            slidBackEnabled: false,
                            pageParam: pageParam
                        })
                    } else if (row.FunType == '配置图表') {
                        api.openWin({
                            name: 'formConfigChart',
                            url: 'common/formConfigChart.html',
                            reload: true,
                            slidBackEnabled: false,
                            pageParam: pageParam
                        })
                    } else if (row.FunType == '配置报表') {
                        api.openWin({
                            name: pageParam.objName + '_0',
                            url: 'common/formConfigReport.html',
                            reload: true,
                            slidBackEnabled: false,
                            pageParam: pageParam
                        })
                    }

                },
                toggleTree(row) {
                    var that = this;
                    that.showList = row.node;
                    that.showLeftPage = false;
                    that.getUndealNum();
                },
                getUndealNum() {
                    var that = this;
                    FLD.ajax('APP_WCLJLTSN', {}, function (res) {
                        for (var i in that.showList) {
                            var x = 0;
                            for (var j in res.ds) {
                                if (that.showList[i].APPFunID == res.ds[j].APPFunID) {
                                    x = 1;
                                    that.$set(that.showList[i], 'unDealNum', res.ds[j].JCNT);
                                }
                            }
                            if (x == 0) {
                                that.$set(that.showList[i], 'unDealNum', 0);
                            }

                        }
                    });
                }
            }
        })
    };
</script>

</html>